// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Collections.Generic;

namespace SnapObjects.Data
{
    internal sealed class DynamicModel<T0, T1> : DynamicModelBase
    {
        private T0 _field0;
        private T1 _field1;

        public DynamicModel() : base(2)
        {

        }

        public DynamicModel(object[] values) : base(values, 2)
        {

        }

        protected override object Getter(int index)
        {
            switch (index)
            {
                case 0:
                    return _field0;
                case 1:
                    return _field1;
                default:
                    throw new IndexOutOfRangeException();
            }
        }

        protected override void Setter(int index, object value)
        {
            switch (index)
            {
                case 0:
                    _field0 = this.GetCompatibleValue<T0>(value);
                    break;
                case 1:
                    _field1 = this.GetCompatibleValue<T1>(value);
                    break;
                default:
                    throw new IndexOutOfRangeException();
            }
        }

        protected override void InitialTypeInfo()
        {
            var list = new List<Type>()
            {
                typeof(T0),
                typeof(T1)
            };

            this.SetTypeInfo(list);
        }
    }
}
